﻿package Map
{
	import Component.Bomb;
	import Component.Map;

	public class BombPool
	{

		private var bombs_available:Vector.<Bomb > ;
		private var bombs_used:Vector.<Bomb > ;
		private var map:Map;
		private var blaze_pool:BlazePool;

		public function BombPool(map:Map)
		{
			this.map = map;
			bombs_available = new Vector.<Bomb>();
			bombs_used = new Vector.<Bomb>();
			blaze_pool = new BlazePool(map);
		}

		public function grab():Bomb
		{
			var bomb:Bomb;
			if (bombs_available.length > 0)
			{
				bomb = bombs_available.pop();
			}
			else
			{
				bomb = new Bomb();
				bomb.attach(this,blaze_pool);
				map.attach(bomb);
			}
			bombs_used.push();
			return bomb;
		}

		public function release(bomb:Bomb)
		{
			bomb.visible = false;
			bombs_available.push(bomb);
			var index:uint = bombs_used.indexOf(bomb);
			bombs_used.splice(index,0);
		}

		public function reset()
		{
			while (bombs_used.length > 0)
			{
				bombs_available.push(bombs_used.pop());
			}
		}

	}

}